<script setup>
import { ref, onMounted } from 'vue'
import { queryPageApi as queryEmpCount } from '@/api/emp'
import { queryAllApi as queryClazzCount } from '@/api/clazz'
import { logApi } from '@/api/log'

// 统计数据
const stats = ref({
  empCount: 0,
  clazzCount: 0,
  logCount: 0
})
// 分页数据
const page = ref({
  name: '',
  begin:'',
  end: '',
  page: 1,
  pageSize: 10
})

// 获取统计数据
const getStats = async () => {
  try {
    // 获取员工总数
    const empRes = await queryEmpCount()
    if (empRes.code == 1) {
      stats.value.empCount = empRes.data.total
    }
    
    // 获取班级总数
    const clazzRes = await queryClazzCount(page.value.name,page.value.begin,page.value.end,page.value.page,page.value.pageSize)
    console.log(clazzRes)
    if (clazzRes.code == 1) {
      stats.value.clazzCount = clazzRes.data.total
    }
    
    // 获取日志总数
    const logRes = await logApi(1, 1)
    if (logRes.code == 1) {
      stats.value.logCount = logRes.data.total
    }
  } catch (error) {
    console.error('获取统计数据失败:', error)
  }
}

// 轮播图数据
const carouselItems = ref([
  {
    id: 1,
    title: '欢迎使用管理系统',
    description: '一站式解决方案，提升管理效率'
  },
  {
    id: 2,
    title: '数据可视化报表',
    description: '直观展示业务数据，辅助决策分析'
  },
  {
    id: 3,
    title: '权限管理系统',
    description: '精细化权限控制，保障数据安全'
  }
])

onMounted(() => {
  getStats()
})
</script>

<template>
  <div class="dashboard-container">
    <!-- 头部区域 -->
    <div class="header-section">
      <h2 class="page-title">系统首页</h2>
    </div>
    
    <!-- 统计卡片 -->
    <el-row :gutter="20" class="stats-section">
      <el-col :span="8">
        <el-card class="stat-card">
          <div class="stat-content">
            <div class="stat-icon bg-primary">
              <i class="el-icon-user"></i>
            </div>
            <div class="stat-info">
              <div class="stat-number">{{ stats.empCount }}</div>
              <div class="stat-label">员工总数</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card class="stat-card">
          <div class="stat-content">
            <div class="stat-icon bg-success">
              <i class="el-icon-office-building"></i>
            </div>
            <div class="stat-info">
              <div class="stat-number">{{ stats.clazzCount }}</div>
              <div class="stat-label">班级数量</div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card class="stat-card">
          <div class="stat-content">
            <div class="stat-icon bg-warning">
              <i class="el-icon-document"></i>
            </div>
            <div class="stat-info">
              <div class="stat-number">{{ stats.logCount }}</div>
              <div class="stat-label">操作日志</div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    
    <!-- 轮播图区域 -->
    <el-card class="carousel-card">
      <template #header>
        <div class="card-header">
          <span>系统介绍</span>
        </div>
      </template>
      
      <el-carousel :interval="5000" arrow="hover" height="300px">
        <el-carousel-item v-for="item in carouselItems" :key="item.id">
          <div class="carousel-item">
            <h3 class="carousel-title">{{ item.title }}</h3>
            <p class="carousel-description">{{ item.description }}</p>
            <div class="carousel-placeholder">
              <i class="el-icon-monitor" style="font-size: 60px; color: #c0c4cc;"></i>
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </el-card>
    
    <!-- 快捷操作 -->
    <el-card class="quick-actions-card">
      <template #header>
        <div class="card-header">
          <span>快捷操作</span>
        </div>
      </template>
      
      <el-row :gutter="20">
        <el-col :span="6">
          <router-link to="/emp">
            <div class="quick-action-item">
              <div class="action-icon bg-primary">
                <i class="el-icon-user"></i>
              </div>
              <div class="action-text">员工管理</div>
            </div>
          </router-link>
        </el-col>
        <el-col :span="6">
          <router-link to="/clazz">
            <div class="quick-action-item">
              <div class="action-icon bg-success">
                <i class="el-icon-school"></i>
              </div>
              <div class="action-text">班级管理</div>
            </div>
          </router-link>
        </el-col>
        <el-col :span="6">
          <router-link to="/empReport">
            <div class="quick-action-item">
              <div class="action-icon bg-warning">
                <i class="el-icon-data-analysis"></i>
              </div>
              <div class="action-text">数据报表</div>
            </div>
          </router-link>
        </el-col>
        <el-col :span="6">
          <router-link to="/log">
            <div class="quick-action-item">
              <div class="action-icon bg-danger">
                <i class="el-icon-document"></i>
              </div>
              <div class="action-text">操作日志</div>
            </div>
          </router-link>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>

<style scoped>
.dashboard-container {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: 100%;
}

.header-section {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding: 15px 20px;
  background-color: #ffffff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
}

.page-title {
  color: #303133;
  font-size: 24px;
  font-weight: 600;
  margin: 0;
}

.stats-section {
  margin-bottom: 20px;
}

.stat-card {
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
  border: none;
  height: 120px;
}

.stat-card :deep(.el-card__body) {
  padding: 0;
}

.stat-content {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 20px;
}

.stat-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 15px;
  font-size: 24px;
  color: white;
  flex-shrink: 0;
}

.bg-primary {
  background: linear-gradient(135deg, #409eff 0%, #64b5f6 100%);
}

.bg-success {
  background: linear-gradient(135deg, #67c23a 0%, #81c784 100%);
}

.bg-warning {
  background: linear-gradient(135deg, #e6a23c 0%, #f5d061 100%);
}

.bg-danger {
  background: linear-gradient(135deg, #f56c6c 0%, #f78989 100%);
}

.stat-info {
  flex: 1;
}

.stat-number {
  font-size: 28px;
  font-weight: 600;
  color: #303133;
  margin-bottom: 5px;
}

.stat-label {
  font-size: 14px;
  color: #909399;
}

.carousel-card,
.quick-actions-card {
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
  border: none;
  margin-bottom: 20px;
}

.carousel-card :deep(.el-card__header),
.quick-actions-card :deep(.el-card__header) {
  padding: 15px 20px;
  border-bottom: 1px solid #ebeef5;
  background-color: #fafafa;
}

.card-header {
  font-size: 16px;
  font-weight: 600;
  color: #303133;
}

.carousel-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
}

.carousel-title {
  font-size: 20px;
  font-weight: 600;
  color: #303133;
  margin: 0 0 15px 0;
}

.carousel-description {
  font-size: 16px;
  color: #606266;
  margin: 0 0 20px 0;
}

.carousel-placeholder {
  width: 100px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f5f7fa;
  border-radius: 50%;
  margin: 0 auto;
}

.quick-action-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0;
  cursor: pointer;
  transition: all 0.3s;
  text-decoration: none;
}

.quick-action-item:hover {
  transform: translateY(-5px);
  background-color: #f8f9fa;
  border-radius: 8px;
}

.action-icon {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  font-size: 20px;
  color: white;
}

.action-text {
  font-size: 14px;
  color: #303133;
  font-weight: 500;
}

a {
  text-decoration: none;
}

@media (max-width: 768px) {
  .dashboard-container {
    padding: 10px;
  }
  
  .header-section {
    padding: 10px 15px;
  }
  
  .page-title {
    font-size: 20px;
  }
  
  .stats-section .el-col {
    margin-bottom: 15px;
  }
  
  .stat-card {
    height: auto;
  }
  
  .stat-content {
    padding: 15px;
  }
  
  .stat-number {
    font-size: 24px;
  }
  
  .carousel-title {
    font-size: 18px;
  }
  
  .carousel-description {
    font-size: 14px;
  }
}
</style>